package org.bpm.view
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	/**
	 * This movieClip is the instance of arrow itself,
	 * this class takes care of the display of the label.
	 * */
	public class ArrowMovieClip extends NodeMovieClip
	{
		public function ArrowMovieClip(pMc:MovieClip)
		{
			super(pMc);
			if(labelField) addChild(labelField);
		}
		public var visibleRect:Rectangle = new Rectangle();
		public var labelPosition:Point = new Point();
		
		override protected function onRemoveFromStage(pEvent:Event):void{
			if(labelField){
				removeChild(labelField);
				labelField = null;
			}
			visibleRect = null;
			labelPosition = null;
			
			super.onRemoveFromStage(pEvent);
		}
		
		override protected function updateView():void{
			mc.x = visibleRect.x;
			mc.y = visibleRect.y;
			mc.rotation = Math.atan2(visibleRect.height, visibleRect.width) * 180/Math.PI;
			
			if(labelField){
				labelField.x = labelPosition.x + visibleRect.x + visibleRect.width/2;
				labelField.y = labelPosition.y + visibleRect.y + visibleRect.height/2;
			}
		}
	}
}